<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
    <xs:element name="LedCenter">
        <xs:complexType>
            <xs:sequence>
                <xs:element ref="Devices" />
            </xs:sequence>
        </xs:complexType>
    </xs:element>
    <xs:element name="Devices">
        <xs:complexType>
            <xs:sequence>
                <xs:element maxOccurs="unbounded" ref="Device"/>
            </xs:sequence>
        </xs:complexType>
    </xs:element>
    <xs:element name="Device">
        <xs:complexType>
            <xs:sequence>
                <xs:choice>
                    <xs:element name="DataTCP" type="IPv4EndpointStruct"/>
                    <xs:element name="DataSMS" type="smsStruct"/>
                </xs:choice>
                <xs:element name="Latitude" type="xs:float"></xs:element>
                <xs:element name="Longtitude" type="xs:float"></xs:element>
            </xs:sequence>
            <xs:attribute name="ID" type="xs:ID"/>
            <xs:attribute name="Name" type="xs:string"/>
            <xs:attribute name="Type" type="deviceEnum"/>
            <xs:attribute name="Password" type="xs:string"/>
        </xs:complexType>
    </xs:element>
    <!-- Defining the base datatype -->
    <xs:simpleType name="IPv4Address">
        <xs:annotation>
            <xs:documentation>
                IPv4 address in the dotted-decimal notation.
            </xs:documentation>
        </xs:annotation>

        <xs:restriction base="xs:string">
            <xs:pattern
                value="((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])"
            />
        </xs:restriction>
    </xs:simpleType>

    <xs:simpleType name="Port">
        <xs:annotation>
            <xs:documentation>
                Port number in the range [1, 65536].
            </xs:documentation>
        </xs:annotation>

        <xs:restriction base="xs:unsignedShort">
            <xs:minInclusive value="1"/>
        </xs:restriction>
    </xs:simpleType>


    <xs:simpleType name="IPv4Endpoint">
        <xs:annotation>
            <xs:documentation>
                IPv4 address and port pair in the form ip:port. IPv4 address is in
                the dotted-decimal notation. Port is in the range [1, 65536].
            </xs:documentation>
        </xs:annotation>

        <xs:restriction base="xs:string">
            <xs:pattern
                value="((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9]):[1-9][0-9]{0,4}"
            />
        </xs:restriction>
    </xs:simpleType>


    <xs:complexType name="IPv4EndpointStruct">
        <xs:annotation>
            <xs:documentation>
                Structured IPv4 address and port pair. IPv4 address is in
                the dotted-decimal notation. Port is in the range [1, 65536].
            </xs:documentation>
        </xs:annotation>

        <xs:sequence>
            <xs:element name="address" type="IPv4Address"/>
            <xs:element name="port" type="Port"/>
        </xs:sequence>
    </xs:complexType>
    <!-- PhoneNmber struct definition -->
    <xs:simpleType name="PhoneNumber">
        <xs:annotation>
            <xs:documentation>
                Telephone  number. Up to 14 digits long.
            </xs:documentation>
        </xs:annotation>

        <xs:restriction base="xs:unsignedLong">
            <xs:minInclusive value="1"/>
            <xs:maxInclusive value="99999999999999"/>
        </xs:restriction>
    </xs:simpleType>
    <!-- Enum device type -->
    <xs:simpleType name="deviceEnum">
        <xs:restriction base="xs:string">
            <xs:enumeration value="TCP"/>
            <xs:enumeration value="SMS"/>
        </xs:restriction>
    </xs:simpleType>
    <xs:simpleType name="smsModeEnum">
        <xs:restriction base="xs:string">
            <xs:enumeration value="PLAIN"/>
            <xs:enumeration value="PDU"/>
        </xs:restriction>
    </xs:simpleType>


    <xs:complexType name="smsStruct">
        <xs:sequence>
            <xs:element name="PhoneNumber" type="PhoneNumber"/>
            <xs:element name="Mode" type="smsModeEnum"/>
        </xs:sequence>
    </xs:complexType>
    
</xs:schema>
